package com.zhuang.springbootnio.thread;

public class Main {
    public static void main(String[] args) {
        // 启动线程池监控
        ThreadPoolMonitor.monitorThreadPool(ThreadPoolConfig.ioThreadPool, "IO线程池");
        ThreadPoolMonitor.monitorThreadPool(ThreadPoolConfig.cpuThreadPool, "CPU线程池");

        // 创建订单服务
        OrderService orderService = new OrderService();

        // 模拟10个订单提交
        for (int i = 1; i <= 10; i++) {
            final int orderNum = i;
            ThreadPoolConfig.ioThreadPool.submit(() -> {
                Order order = new Order("ORD-" + orderNum, "USER-" + orderNum, 100.0 * orderNum);
                orderService.submitOrder(order);
            });

            try {
                Thread.sleep(200); // 模拟订单提交间隔
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        // 程序运行一段时间后关闭线程池
        try {
            Thread.sleep(30000); // 运行30秒
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // 关闭线程池
        ThreadPoolMonitor.shutdownThreadPool(ThreadPoolConfig.ioThreadPool, "IO线程池");
        ThreadPoolMonitor.shutdownThreadPool(ThreadPoolConfig.cpuThreadPool, "CPU线程池");
    }
}